
package com.scs.application.modules.upms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.BaseController;
import com.scs.application.modules.upms.entity.OnlineUser;
import com.scs.application.modules.upms.request.OnlineUserQueryRequest;
import com.scs.application.modules.upms.service.LogoutService;
import com.scs.application.modules.upms.service.OnlineUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线用户 controller
 *
 */
@AllArgsConstructor
@RestController
@RequestMapping("/upms/online_users")
public class OnlineUserController extends BaseController {

    private final OnlineUserService onlineUserService;

    private final LogoutService logoutService;


    @GetMapping("/page")
    public PageResult page(OnlineUserQueryRequest request) {
        IPage page = onlineUserService.page(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }


    @DeleteMapping("/kickout/{id}")
    public CommonResult<List> kickoutSingle(@PathVariable String id) {
        OnlineUser onlineUser = onlineUserService.getById(id);
        if (onlineUser == null) {
            return CommonResult.error("踢出失败");
        }
        logoutService.logout(onlineUser.getToken(),false);

        return CommonResult.ok("踢出成功");
    }


}
